#ifndef TRACE_H__
#define TRACE_H__

#define TRACE_LEVEL_DEBUG      5
#define TRACE_LEVEL_INFO       4
#define TRACE_LEVEL_WARNING    3
#define TRACE_LEVEL_ERROR      2
#define TRACE_LEVEL_FATAL      1

#define WHERESTR  "[%s:%d]\n"
#define WHEREARG  __FILE__, __LINE__

/* DECLARATION  of external variable. Does not allocate storage.
 * To be  DEFINED in ONLY ONE source .c file
 */
extern unsigned int traceLevel;

// Trace output depends on traceLevel value
#define TRACE_DEBUG(...)	\
		do { \
			if (TRACE_LEVEL_DEBUG <= traceLevel)   { \
			    printf(WHERESTR, WHEREARG); \
				printf("-D- " __VA_ARGS__); \
			} \
		} while(0)

#define TRACE_INFO(...) \
		do {\
			if (TRACE_LEVEL_INFO <= traceLevel)    {\
				printf("-I- " __VA_ARGS__); \
			} \
		} while (0)

#define TRACE_WARNING(...)	\
		do {\
			if (TRACE_LEVEL_WARNING <= traceLevel) {\
			    printf(WHERESTR, WHEREARG); \
				printf("-W- " __VA_ARGS__); \
			} \
		} while(0)

#define TRACE_ERROR(...)	\
		do { \
			if (TRACE_LEVEL_ERROR <= traceLevel)   {\
			    printf(WHERESTR, WHEREARG); \
				printf("-E- " __VA_ARGS__); \
			} \
		} while(0)

#define TRACE_FATAL(...)	\
		do { \
			if (TRACE_LEVEL_FATAL <= traceLevel)   { \
			    printf(WHERESTR, WHEREARG); \
				printf("-F- " __VA_ARGS__); \
				while(1); \
			} \
		} while(0)

#define TRACE_THIS(...)	\
		do { \
			printf(__VA_ARGS__); \
		} \
		while(0)

#endif // TRACE_H__
